package com.etong.citymap.activity;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.etong.citymap.bean.AssignmentBean;
import com.etong.citymap.connect.HttpSendData;
import com.etong.citymap.db.util.CityApplication;
import com.etong.citymap.util.StringUtil;
import com.etong.citymap.util.log.LogUtil;

/**
 * 执法通申请退办
 */
public class LawTBActivity extends Activity implements OnClickListener {
	Button tb_back;
	Button tb_enter;
	EditText tb_name;
	EditText tb_ly;
	AssignmentBean bean;
	private CityApplication cityApplication;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		cityApplication = (CityApplication)getApplication();
		setContentView(R.layout.lawtb);
		tb_back = (Button) findViewById(R.id.tb_back);
		tb_enter = (Button) findViewById(R.id.tb_enter);
		tb_back.setOnClickListener(this);
		tb_enter.setOnClickListener(this);
		tb_name = (EditText) findViewById(R.id.tb_name);
		tb_ly = (EditText) findViewById(R.id.tb_ly);
		tb_name.setText(cityApplication.getZFTUserName());
		bean = (AssignmentBean) this.getIntent().getSerializableExtra("bean");
	}

	@Override
	public void onClick(View v) {
		if (tb_back == v) {
			finish();
		}
		if (tb_enter == v) {
			UpLoadData loadData=new UpLoadData();
			loadData.execute();
		}

	}

	class UpLoadData extends AsyncTask<String, String, String> {

		
		@Override
		protected void onPostExecute(String result) {
			if (StringUtil.IsNotNull(result)) {
				if (result.equals("-1") || result.equals("-2")) {
					Toast.makeText(LawTBActivity.this, "服务器出错",
							Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(LawTBActivity.this, "上传成功",
							Toast.LENGTH_SHORT).show();
					setResult(100);
					finish();
				}
			} else {
				Toast.makeText(LawTBActivity.this, "上传服务器出错",
						Toast.LENGTH_SHORT).show();

			}
			super.onPostExecute(result);
		}
		@Override
		protected String doInBackground(String... params) {
			String yj = tb_ly.getText().toString();
			if (StringUtil.IsNotNull(yj)) {
				String url = "supervisor/ashx/czabnormal.ashx"; // 001 001
				Map<String, String> map = new HashMap<String, String>();
				map.put("Prjid", bean.getPrjid());
				map.put("Actinsid", bean.getActinsid());
				map.put("Insid", bean.getInsid());
				map.put("Wfid", bean.getWfid());
				map.put("assignid", bean.getAssignid());
				map.put("userid",cityApplication.getZFTUserId());
				map.put("Status", com.etong.citymap.util.Status.ZFTTB + "");
				map.put("Idea", yj);
				map.put("Username", cityApplication.getZFTUserName());
				try {
					String result = HttpSendData.SendGet(url, map, "utf-8",cityApplication.getHTTPURL());
                       return result;
				} catch (Exception e) {
					LogUtil.e(e);
				}

			}

			return null;
		}

	}

}
